import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

// const debug = process.env.NODE_ENV !== 'production'

const getMappedRoutes = (r) => (
  r.map(route => ({
    ...route,
    component: (resolve) => require([`../pages/${route.page}`], resolve),
    children: route.children ? getMappedRoutes(route.children) : undefined
  }))
)

let baseRoutes = [{
  path: '/',
  name: '首页',
  page: 'App.vue',
  children: [{
    path: '/ArticleUpload',
    name: '文章上传',
    page: 'ArticleUpload.vue'
  }, {
    path: '/HeroUpload',
    name: '英雄列表',
    page: 'HeroUpload.vue'
  }, {
    path: '/InsUpload',
    name: '铭文列表',
    page: 'InsUpload.vue'
  }, {
    path: '/EquipUpload',
    name: '装备列表',
    page: 'EquipUpload.vue'
  }]
}]

export const router = new VueRouter({
  mode: 'hash',
  routes: getMappedRoutes(baseRoutes),
  beforeEach: function (to, from, next) {
    console.error('before')
    // next(false)
  }
})